<template>
	<view>
		<u-sticky bgColor="#f5f5f5">
			<view class="searchchild">
				<u-search placeholder="请输入搜索关键词" v-model="keyword" @search="getlist" :showAction="false"></u-search>
			</view>
			<u-tabs :list="list2" @change="tabchange" lineColor="#F5AC4F" :activeStyle="{
				color: '#333333',
				fontWeight: 'bold',
				transform: 'scale(1.05)'
				}" :inactiveStyle="{
				color: '#999999',
				fontWeight: 'bold',
				}"></u-tabs>
		</u-sticky>
		<view class="flexcenter" style="margin-top: 300rpx;" v-if="!list.data.length">
			<view class="placeholderimage"></view>
		</view>
		<view class="box" style="padding-bottom: 120rpx;">
			<view class="classification" v-for="(item,index) in list.data" @click="getCommodityDetail(item.id)">
				<view class="img">
					<image :src="item.image_text" mode=""></image>
				</view>
				<view class="detailed">
					<view class="info">
						<view class="overhidden xiankuan">{{item.name}}</view>
					</view>
					<!-- <view class="flexbetween zdy margin_top1">
						<view class="">库存:{{item.goods_num || 0}}</view>
						<view class="">月销{{item.mouth_sales || 0}}</view>
					</view> -->
					<view class="foot margin_top1">
						<view class="xiaohuang">兑换：{{item.smallgoodsunit.priceinfo.dh_score || 0}}分</view>
					</view>
				</view>
			</view>
		</view>
		<view class="posibottom" style="bottom: 30rpx;">
			<view class="onebox flexcenter flex_wrap">
				<view class="huangse">可用积分：{{total_score}}分</view></view>
		</view>
	</view>
</template>

<script>
	import httpRequest from '@/commonFun/httpRequest.js'
	export default {
		data() {
			return {
				keyword:'',
				page:1,
				limit:10,
				list:{
					data:[],
				},
				list2: [], //分类列表
				fenleiId:"",
				total_score:0,
			}
		},
		onLoad() {
			this.getlist()
			this.fenlei()
		},
		onShow() {
			this.userMy()
		},
		methods: {
			// 调取我的接口
			userMy() {
				let _this = this
				httpRequest.request('/customapi/user/index', 'POST', {}).then(res => {
					this.total_score = res.data.total_score
				})
			},
			tabchange(item) {
				// console.log(item);
				this.fenleiId = item.id;
				this.getlist();
			},
			//商品分类
			fenlei() {
				let _this = this;
				httpRequest.request('/customapi/goods/goodsCategory', 'GET', {}).then(res => {
					if (res.code == 1) {
						let arr = []
						res.data.forEach(item => {
							arr.push({
								id: item.id,
								name: item.name
							})
						})
						arr.unshift({
							id: "",
							name: "全部"
						})
						this.list2 = arr
						// this.fenleiId = this.list2[0].id
						_this.getlist(); //商品列表
					} else {
						httpRequest.toast(res.msg)
					}
				})
			},
			//添加购物车
			addCart(item) {
				let _this = this;
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: '/pages/login/logintwice'
					})
					return;
				}
				httpRequest.request('/customapi/cart/addCart', 'GET', {
					goods_id: item.id,
					number: 1,
					sku_id: item.smallgoodsunit.priceinfo.id
				}).then(res => {
					httpRequest.toast(res.msg)
				})
			},
			getCommodityDetail(i) {
				uni.navigateTo({
					url: '/pages/index/commodityDetail/commodityDetail?id=' + i+"&type=2",
				});
			},
			getlist(isPage, page) {
				let _this = this;
				httpRequest.request('/customapi/goods/index', 'POST', {
					category_id: _this.fenleiId,
					page: page || 1,
					limit: _this.limit,
					keyword: this.keyword,
					is_scoredh: 1,
				}).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data.push(...resList.data);
						} else {
							_this.list = res.data;
							_this.list.data = resList.data;
						}
					} else {
						httpRequest.toast(res.msg);
					}
				})
			},
			onReachBottom(){
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.lastpage <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.getdata(true, page);
			},
		}
	}
</script>

<style scoped lang="scss">
	.searchchild {
		width: 100%;
		box-sizing: border-box;
		padding: 30rpx;
		font-size: 28rpx
	}
	.headerLeft {
		padding-top: 30rpx;
		margin: 30rpx;
		border-radius: 50rpx;
		background-color: #fff;
		padding: 10rpx 30rpx;
		font-size: 32rpx;
		margin-right: 30rpx;
	}
	.box {
		display: flex;
		justify-content: space-between;
		padding: 23rpx;
		flex-wrap: wrap;
	
		.classification {
			margin-bottom: 20rpx;
			width: 340rpx;
			// background-color: red;
			border-radius: 25rpx 0px 25rpx 0px;
			overflow: hidden;
	
			.img {
				position: relative;
	
				.d1 {
					font-size: 28rpx !important;
					font-family: PingFang SC !important;
					color: #FFFFFF !important;
					position: absolute;
					top: 0;
					left: 0;
					background-color: #FF0000;
					padding: 4rpx 20rpx;
					font-weight: 800 !important;
					border-radius: 25rpx 0px 25rpx 0px;
				}
	
				.d2 {
					font-size: 28rpx !important;
					font-family: PingFang SC;
					font-weight: 800 !important;
					color: #FFFFFF !important;
					position: absolute;
					bottom: 16rpx;
					right: 10rpx;
				}
	
				image {
					border-radius: 25rpx 25rpx 0 0px;
					width: 100%;
					height: 340rpx;
				}
			}
		}
	
		.detailed {
			background-color: #ffffff;
			padding: 20rpx;
			font-size: 28rpx;
			.info,
			.detail,
			.integral {
				display: inline-block;
			}
	
			.info {
				font-size: 32rpx !important;
				font-family: PingFang SC;
				font-weight: 800;
				color: #333333;
			}
	
			.integral {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 800;
				color: #999999;
			}
	
			.detail {
				background-color: #f5ac4f;
				color: #ffffff;
				margin-right: 10rpx;
				font-size: 28rpx;
				border-radius: 7rpx;
			}
		}
	
		.foot {
			background-color: #ffffff;
			font-size: 28rpx !important;
			display: flex;
			justify-content: space-between;
			color: #ff0000;
		}
	}
</style>
